package com.shiguiwu.springmybatis.spring.conditional;

import com.shiguiwu.springmybatis.spring.conditional.annotation.MyEnvCondition;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

import java.util.Objects;

/**
 * @description: 根据环境是否生效这个bean
 * @author: stone
 * @date: Created by 2021/10/8 22:00
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.spring.conditional
 */
public class EnvCondition implements Condition {


    @Override
    public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata metadata) {
        //这里为了方便测试，写死一个环境
        MyEnvCondition.Env curEnv = MyEnvCondition.Env.DEV;
        MyEnvCondition.Env value = (MyEnvCondition.Env) Objects.requireNonNull(metadata.getAllAnnotationAttributes(MyEnvCondition.class.getName())).get("value").get(0);

        return curEnv.equals(value);
    }



}
